package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {


    //添加菜品或套餐到购物车
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) VALUE " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},now())")
    public void add(ShoppingCart shoppingCart);

    //查询购物车中的所有商品
    @Select("select * from shopping_cart where user_id = #{userId} ")
    public List<ShoppingCart> find(Long userId);

    //根据菜品id或套餐id查询购物车数据
    public ShoppingCart findById(ShoppingCart shoppingCart);

    //修改菜品或套餐的份数
    public void update(ShoppingCart cart);

    //删除购物车中一份商品
    public void delete(ShoppingCart shoppingCart);

    //清空购物车
    @Delete("delete from shopping_cart where user_id = #{userId" +
            "}")
    public void clean(Long userId);
}
